package com.exercise240710.controller;

import com.exercise240710.DTO.ReportStudentPhysicalDTO;
import com.exercise240710.DTO.StudentPhysicalDTO;
import com.exercise240710.entity.PhysicalTest;
import com.exercise240710.entity.StudentInfo;
import com.exercise240710.service.ReconfigrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ReconfigrationController {

    @Autowired
    private ReconfigrationService reconfigrationService;


    @GetMapping("/test")
    private @ResponseBody List<PhysicalTest>
    test(@RequestParam("id1") Long id1, @RequestParam("id2") Long id2) {
        List<Long> tmp = new ArrayList<>();
        tmp.add(id1);
        tmp.add(id2);
        return reconfigrationService.testTest(tmp);
    }

    @GetMapping("/queryST/{pageSize}/{pageNum}")
    private @ResponseBody List<StudentPhysicalDTO>
    queryQT(
            @RequestParam(value = "min_id", required = false) Long min_id,
            @RequestParam(value = "max_id", required = false) Long max_id,
            @RequestParam(value = "id_seq", required = false) String id_seq,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "gender", required = false) String gender,
            @RequestParam(value = "min_age", required = false) Short min_age,
            @RequestParam(value = "max_age", required = false) Short max_age,
            @RequestParam(value = "school", required = false) String school,
            @RequestParam(value = "min_student_num", required = false) Integer min_student_num,
            @RequestParam(value = "max_student_num", required = false) Integer max_student_num,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "live_place", required = false) String live_place,
            @RequestParam(value = "iban", required = false) String iban,
            @PathVariable(value = "pageSize") Integer pageSize,
            @PathVariable(value = "pageNum") Long pageNum
    ) {
        return reconfigrationService.findStudentPhysicalJoin(
                min_id, max_id, id_seq,
                name, gender, min_age,
                max_age, school, min_student_num,
                max_student_num, subject, phone,
                email, live_place, iban,
                pageSize, pageNum
        );
    }

    @GetMapping("/reportST/{pageSize}/{pageNum}")
    private @ResponseBody List<ReportStudentPhysicalDTO>
    reportST(
            @RequestParam(value = "min_id", required = false) Long min_id,
            @RequestParam(value = "max_id", required = false) Long max_id,
            @RequestParam(value = "id_seq", required = false) String id_seq,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "gender", required = false) String gender,
            @RequestParam(value = "min_age", required = false) Short min_age,
            @RequestParam(value = "max_age", required = false) Short max_age,
            @RequestParam(value = "school", required = false) String school,
            @RequestParam(value = "min_student_num", required = false) Integer min_student_num,
            @RequestParam(value = "max_student_num", required = false) Integer max_student_num,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "live_place", required = false) String live_place,
            @RequestParam(value = "iban", required = false) String iban,
            @PathVariable(value = "pageSize") Integer pageSize,
            @PathVariable(value = "pageNum") Long pageNum
    ) {
        return reconfigrationService.reportStudentPhysical(
                min_id, max_id, id_seq,
                name, gender, min_age,
                max_age, school, min_student_num,
                max_student_num, subject, phone,
                email, live_place, iban,
                pageSize, pageNum
        );
    }

    @GetMapping("/findStudentByCondition/{pageSize}/{pageNum}")
    private @ResponseBody List<StudentInfo>
    findStudentByCondition(
            @RequestParam(value = "min_id", required = false) Long min_id,
            @RequestParam(value = "max_id", required = false) Long max_id,
            @RequestParam(value = "id_seq", required = false) String id_seq,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "gender", required = false) String gender,
            @RequestParam(value = "min_age", required = false) Short min_age,
            @RequestParam(value = "max_age", required = false) Short max_age,
            @RequestParam(value = "school", required = false) String school,
            @RequestParam(value = "min_student_num", required = false) Integer min_student_num,
            @RequestParam(value = "max_student_num", required = false) Integer max_student_num,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "live_place", required = false) String live_place,
            @RequestParam(value = "iban", required = false) String iban,
            @PathVariable(value = "pageSize") Integer pageSize,
            @PathVariable(value = "pageNum") Long pageNum
    ) {
        return reconfigrationService.findStudentByCondition(
                min_id, max_id, id_seq,
                name, gender, min_age,
                max_age, school, min_student_num,
                max_student_num, subject, phone,
                email, live_place, iban,
                pageSize, pageNum
        );
    }

    @PostMapping("/updateStudent")
    private @ResponseBody int updateStudent(
            @RequestParam(value = "id_seq") String id_seq,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "min_id", required = false) String gender,
            @RequestParam(value = "age", required = false) Short age,
            @RequestParam(value = "school", required = false) String school,
            @RequestParam(value = "student_num", required = false) Integer student_num,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "live_space", required = false) String live_place,
            @RequestParam(value = "iban", required = false) String iban
    ) {
        return reconfigrationService.updateStudent(
                id_seq, name, gender, age, school, student_num,
                subject, phone, email, live_place, iban
        );
    }

    @PostMapping("/addStudent")
    private @ResponseBody int
    addStudent(
            @RequestParam(value = "id_seq") String id_seq,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "min_id", required = false) String gender,
            @RequestParam(value = "age", required = false) Short age,
            @RequestParam(value = "school", required = false) String school,
            @RequestParam(value = "student_num", required = false) Integer student_num,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "live_space", required = false) String live_place,
            @RequestParam(value = "iban", required = false) String iban
    ) {
        return reconfigrationService.addStudent(
                id_seq, name, gender, age, school, student_num,
                subject, phone, email, live_place, iban);
    }

    @PostMapping("/deletePhysicalByIdSeq")
    private @ResponseBody int
    deletePhysicalByIdSeq(@RequestParam(value = "id_seq") String id_seq) {
        return reconfigrationService.deletePhysicalByIdSeq(id_seq);
    }

    @PostMapping("/deleteStudentByIdSeq")
    private @ResponseBody int
    deleteStudentByIdSeq(@RequestParam(value = "id_seq") String id_seq) {
        return reconfigrationService.deleteStudentByIdSeq(id_seq);
    }

    @GetMapping("/findPhysicalByCondition/{pageSize}/{pageNum}")
    private @ResponseBody List<PhysicalTest>
    selectPhysicalByCondition(
            @RequestParam(value = "min_id", required = false) Long min_id,
            @RequestParam(value = "max_id", required = false) Long max_id,
            @RequestParam(value = "id_seq", required = false) String id_seq,
            @RequestParam(value = "min_height", required = false) Float min_height,
            @RequestParam(value = "max_height", required = false) Float max_height,
            @RequestParam(value = "min_weight", required = false) Float min_weight,
            @RequestParam(value = "max_weight", required = false) Float max_weight,
            @RequestParam(value = "min_vital_capacity", required = false) Short min_vital_capacity,
            @RequestParam(value = "max_vital_capacity", required = false) Short max_vital_capacity,
            @RequestParam(value = "min_seated_forward_bend", required = false) Float min_seated_forward_bend,
            @RequestParam(value = "max_seated_forward_bend", required = false) Float max_seated_forward_bend,
            @RequestParam(value = "min_standing_long_jump", required = false) Short min_standing_long_jump,
            @RequestParam(value = "max_standing_long_jump", required = false) Short max_standing_long_jump,
            @RequestParam(value = "min_rush_50", required = false) Float min_rush_50,
            @RequestParam(value = "max_rush_50", required = false) Float max_rush_50,
            @RequestParam(value = "min_long_distance_run", required = false) Float min_long_distance_run,
            @RequestParam(value = "max_long_distance_run", required = false) Float max_long_distance_run,
            @RequestParam(value = "min_sit_ups", required = false) Short min_sit_ups,
            @RequestParam(value = "max_sit_ups", required = false) Short max_sit_ups,
            @RequestParam(value = "test_date", required = false) String test_date,
            @RequestParam(value = "min_student_id", required = false) Long min_student_id,
            @RequestParam(value = "max_student_id", required = false) Long max_student_id,
            @PathVariable(value = "pageSize") Integer pageSize,
            @PathVariable(value = "pageNum") Long pageNum
    ) {
        return reconfigrationService.findPhysicalByCondition(
                min_id, max_id, id_seq, min_height,
                max_height, min_weight, max_weight,
                min_vital_capacity, max_vital_capacity,
                min_seated_forward_bend, max_seated_forward_bend,
                min_standing_long_jump, max_standing_long_jump,
                min_rush_50, max_rush_50, min_long_distance_run,
                max_long_distance_run, min_sit_ups, max_sit_ups,
                test_date, min_student_id, max_student_id,
                pageSize, pageNum
        );
    }

    @PostMapping("/addPhysical")
    private @ResponseBody int
    addPhysical(
            @RequestParam(value = "id_seq") String id_seq,
            @RequestParam(value = "height", required = false) Float height,
            @RequestParam(value = "weight", required = false) Float weight,
            @RequestParam(value = "vital_capacity", required = false) Short vital_capacity,
            @RequestParam(value = "seated_forward_bend", required = false) Float seated_forward_bend,
            @RequestParam(value = "standing_long_jump", required = false) Short standing_long_jump,
            @RequestParam(value = "rush_50", required = false) Float rush_50,
            @RequestParam(value = "long_distance_run", required = false) Float long_distance_run,
            @RequestParam(value = "sit_ups", required = false) Short sit_ups,
            @RequestParam(value = "test_date", required = false) String test_date
    ) {
        return reconfigrationService.addPhysical(id_seq, height, weight, vital_capacity,
                seated_forward_bend, standing_long_jump,
                rush_50, long_distance_run, sit_ups, test_date
        );
    }
}
